package com.ruoyi.wcf.controller;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wcf.domain.WcfWareHouse;
import com.ruoyi.wcf.service.IWcfWareHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库管理Controller
 *
 * @author zhipeng
 * @date 2022-04-06
 */
@RestController
@RequestMapping("/wcf/WcfWareHouse")
public class WcfWareHouseController extends BaseController
{
    @Autowired
    private IWcfWareHouseService wcfWareHouseService;
    @Autowired
    private ISysUserService userService;

    /**
     * 查询仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfWareHouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(WcfWareHouse wcfWareHouse)
    {
        startPage();
        List<WcfWareHouse> list = wcfWareHouseService.selectWcfWareHouseList(wcfWareHouse);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfWareHouse:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WcfWareHouse wcfWareHouse)
    {
        List<WcfWareHouse> list = wcfWareHouseService.selectWcfWareHouseList(wcfWareHouse);
        ExcelUtil<WcfWareHouse> util = new ExcelUtil<WcfWareHouse>(WcfWareHouse.class);
        return util.exportExcel(list, "仓库管理数据");
    }

    /**
     * 获取仓库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfWareHouse:query')")
    @GetMapping(value = "/{houseId}")
    public AjaxResult getInfo(@PathVariable("houseId") Long houseId)
    {
        return AjaxResult.success(wcfWareHouseService.selectWcfWareHouseByHouseId(houseId));
    }

    /**
     * 新增仓库管理
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfWareHouse:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WcfWareHouse wcfWareHouse)
    {
        if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(wcfWareHouse.getHouseAccount())))
        {
            return AjaxResult.error("新增用户'" + wcfWareHouse.getHouseAccount() + "'失败，登录账号已存在");
        }
        return toAjax(wcfWareHouseService.insertWcfWareHouse(wcfWareHouse));
    }

    /**
     * 修改仓库管理
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfWareHouse:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WcfWareHouse wcfWareHouse)
    {
        return toAjax(wcfWareHouseService.updateWcfWareHouse(wcfWareHouse));
    }

    /**
     * 删除仓库管理
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfWareHouse:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{houseIds}")
    public AjaxResult remove(@PathVariable Long[] houseIds)
    {
        return toAjax(wcfWareHouseService.deleteWcfWareHouseByHouseIds(houseIds));
    }
}
